package xcmg.device.dao.entity.sfModel;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import xcmg.device.DeviceServiceApplication;
import xcmg.device.dao.entity.purchase.PurchaseRequestDO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZHANGK
 * @date 2020/10/15
 *
 * 顺丰接口 PURCHASE_ORDER_SERVICE 服务实体类
 *
 **/
@Data
public class PurchaseOrderRequestDO {

    @JacksonXmlProperty(localName = "CompanyCode")
    private String companyCode;

    @JacksonXmlElementWrapper(localName = "PurchaseOrders")
    @JacksonXmlProperty(localName = "PurchaseOrder")
    private List<PurchaseOrderDO> purchaseOrderDOList;

    public static void main(String[] args) throws JsonProcessingException {

        ObjectMapper xmlMapper = new XmlMapper();
        xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        xmlMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
        xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
        xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING);


        PurchaseOrderRequestDO purchaseOrderRequestDO = new PurchaseOrderRequestDO();
        purchaseOrderRequestDO.setCompanyCode("1002");
        List<PurchaseOrderDO> purchaseOrderDOS = new ArrayList<>();
        PurchaseOrderDO purchaseOrderDO = new PurchaseOrderDO();
        purchaseOrderDO.setErpOrder("123");
        purchaseOrderDO.setErpOrderType("1");
        purchaseOrderDO.setWarehouseCode("4001");
        purchaseOrderDOS.add(purchaseOrderDO);
        purchaseOrderRequestDO.setPurchaseOrderDOList(purchaseOrderDOS);

        String xml = xmlMapper.writeValueAsString(purchaseOrderRequestDO);
        System.out.println(xml);


    }


}
